/*
 * Principal.java
 *
 * Created on 16 de Outubro de 2007, 22:43
 */
package Principal;
/**
 *
 * @author  kurumin
 */
import cadastro.*;
import classes.data;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import bd.*;
import relatorios.JasperReportExemplo;

public class Principal extends javax.swing.JFrame {
    
    /** Creates new form Principal */
    public Principal() {
        initComponents();
        /*bd = new Database();
        Settings settings = new Settings();
        if( !settings.readSettings(nameXml))
        {
            EditSettings edtSettings = new EditSettings(nameXml);
            edtSettings.setVisible(true);
        }
        if( !settings.readSettings(nameXml))
            return;
        bd.settings = settings;
        if( !bd.connect()){
            JOptionPane.showMessageDialog(null,bd.ErrorMessage);
            return;
        }*/
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpBotoes = new javax.swing.JPanel();
        jbCadCliente = new javax.swing.JButton();
        jbCadReserva = new javax.swing.JButton();
        jbCalculadora = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        JMBprincipal = new javax.swing.JMenuBar();
        jmCadastro = new javax.swing.JMenu();
        jmiCadClientes = new javax.swing.JMenuItem();
        jmiCadFilmes = new javax.swing.JMenuItem();
        jmiCadFunc = new javax.swing.JMenuItem();
        jmiCadReserva = new javax.swing.JMenuItem();
        jmiCadSalas = new javax.swing.JMenuItem();
        jmiCadSessao = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jmiSair = new javax.swing.JMenuItem();
        jmRelatorios = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jmUtilitarios = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jmAjuda = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Cinemax");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });
        getContentPane().setLayout(null);

        jpBotoes.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jbCadCliente.setText("Cad. Clientes");
        jbCadCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCadClienteActionPerformed(evt);
            }
        });

        jbCadReserva.setText("Cad.Reserva");
        jbCadReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCadReservaActionPerformed(evt);
            }
        });

        jbCalculadora.setText("Calculadora");
        jbCalculadora.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCalculadoraActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpBotoesLayout = new javax.swing.GroupLayout(jpBotoes);
        jpBotoes.setLayout(jpBotoesLayout);
        jpBotoesLayout.setHorizontalGroup(
            jpBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpBotoesLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(jbCadCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(66, 66, 66)
                .addComponent(jbCadReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
                .addComponent(jbCalculadora, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34))
        );
        jpBotoesLayout.setVerticalGroup(
            jpBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpBotoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbCalculadora, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
                    .addComponent(jbCadCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbCadReserva, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        getContentPane().add(jpBotoes);
        jpBotoes.setBounds(10, 10, 620, 70);

        jPanel1.setLayout(new java.awt.GridLayout(0, 4, 10, 10));
        jScrollPane1.setViewportView(jPanel1);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(10, 90, 1000, 590);

        jmCadastro.setMnemonic('C');
        jmCadastro.setText("Cadastros");

        jmiCadClientes.setText("Clientes");
        jmiCadClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCadClientesActionPerformed(evt);
            }
        });
        jmCadastro.add(jmiCadClientes);

        jmiCadFilmes.setText("Filmes");
        jmiCadFilmes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCadFilmesActionPerformed(evt);
            }
        });
        jmCadastro.add(jmiCadFilmes);

        jmiCadFunc.setText("Funcionarios");
        jmiCadFunc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCadFuncActionPerformed(evt);
            }
        });
        jmCadastro.add(jmiCadFunc);

        jmiCadReserva.setText("Reserva");
        jmiCadReserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCadReservaActionPerformed(evt);
            }
        });
        jmCadastro.add(jmiCadReserva);

        jmiCadSalas.setText("Salas");
        jmiCadSalas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCadSalasActionPerformed(evt);
            }
        });
        jmiCadSalas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jmiCadSalasMouseClicked(evt);
            }
        });
        jmCadastro.add(jmiCadSalas);

        jmiCadSessao.setText("Sessão");
        jmiCadSessao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCadSessaoActionPerformed(evt);
            }
        });
        jmCadastro.add(jmiCadSessao);
        jmCadastro.add(jSeparator1);

        jmiSair.setMnemonic('S');
        jmiSair.setText("Sair");
        jmiSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSairActionPerformed(evt);
            }
        });
        jmCadastro.add(jmiSair);

        JMBprincipal.add(jmCadastro);

        jmRelatorios.setMnemonic('R');
        jmRelatorios.setText("Relatórios");

        jMenuItem2.setText("Reservas");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jmRelatorios.add(jMenuItem2);

        jMenuItem3.setText("Caixa");
        jmRelatorios.add(jMenuItem3);

        JMBprincipal.add(jmRelatorios);

        jmUtilitarios.setMnemonic('U');
        jmUtilitarios.setText("Utilitários");

        jMenuItem1.setText("Calculadora");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jmUtilitarios.add(jMenuItem1);

        JMBprincipal.add(jmUtilitarios);

        jmAjuda.setMnemonic('A');
        jmAjuda.setText("Ajuda");
        jmAjuda.setToolTipText("");
        JMBprincipal.add(jmAjuda);

        setJMenuBar(JMBprincipal);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1026)/2, (screenSize.height-735)/2, 1026, 735);
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem1ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem1ActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new novo().setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jmiSairActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmiSairActionPerformed
    {//GEN-HEADEREND:event_jmiSairActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        Principal.this.dispose();
    }//GEN-LAST:event_jmiSairActionPerformed

    private void jmiCadReservaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmiCadReservaActionPerformed
    {//GEN-HEADEREND:event_jmiCadReservaActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new cadReservas(bd).setVisible(true);
    }//GEN-LAST:event_jmiCadReservaActionPerformed

    private void jbCadReservaActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbCadReservaActionPerformed
    {//GEN-HEADEREND:event_jbCadReservaActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new cadReservas(bd).setVisible(true);
    }//GEN-LAST:event_jbCadReservaActionPerformed

    private void jbCalculadoraActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbCalculadoraActionPerformed
    {//GEN-HEADEREND:event_jbCalculadoraActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:

    }//GEN-LAST:event_jbCalculadoraActionPerformed

    private void jmiCadSessaoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmiCadSessaoActionPerformed
    {//GEN-HEADEREND:event_jmiCadSessaoActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new cadSessao(bd).setVisible(true);
    }//GEN-LAST:event_jmiCadSessaoActionPerformed

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
// TODO add your handling code here:
        this.jPanel1.removeAll();
        ResultSet rs = null;
        data d = new data();
        String date = d.geradata();
        String sql=("SELECT filme.titulo,filme.imag_cartaz FROM filme WHERE (data_estreia + tempo_cartaz) > '"+date+"';");
       rs = bd.executeQueryRs(sql);
              
        if (rs != null){
            try {
                while (rs.next()){
                   String titulo = rs.getString("titulo");
                   String ende   = rs.getString("imag_cartaz");
                   JButton button =( new JButton(titulo,new ImageIcon(path+ende)));
                   button.setVerticalTextPosition(SwingConstants.TOP);
                   button.setHorizontalTextPosition(SwingConstants.CENTER);              
                   this.jPanel1.add(button);
                }            
            } catch (SQLException ex) {
                ex.printStackTrace();
            }            
        }
    }//GEN-LAST:event_formWindowGainedFocus

    private void jmiCadSalasActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmiCadSalasActionPerformed
    {//GEN-HEADEREND:event_jmiCadSalasActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new cadSala(bd).setVisible(true);
    }//GEN-LAST:event_jmiCadSalasActionPerformed

    private void jbCadClienteActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jbCadClienteActionPerformed
    {//GEN-HEADEREND:event_jbCadClienteActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new cadCliente(bd).setVisible(true);
    }//GEN-LAST:event_jbCadClienteActionPerformed

    private void jmiCadClientesActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmiCadClientesActionPerformed
    {//GEN-HEADEREND:event_jmiCadClientesActionPerformed
       // TODO adicione seu c?digo de manipula??o aqui:
        new cadCliente(bd).setVisible(true);
    }//GEN-LAST:event_jmiCadClientesActionPerformed

    private void jmiCadFuncActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCadFuncActionPerformed
         new cadFuncionarios(bd).setVisible(true);
    }//GEN-LAST:event_jmiCadFuncActionPerformed

    private void jmiCadFilmesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCadFilmesActionPerformed
// TODO adicione seu c?digo de manipula??o aqui:
        new cadFilmes(bd, this.path).setVisible(true);
    }//GEN-LAST:event_jmiCadFilmesActionPerformed
    
    private void timer1OnTime(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_timer1OnTime
        Date hoje = new Date();     
        Locale brasil = new Locale ("pt","BR");
        DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, brasil);
        //System.out.println("Hoje no Brasil: "+ df.format(hoje));
        DateFormat formato = new SimpleDateFormat("HH:mm:ss.SSS");  
        String formattedDate = formato.format(hoje);  
    }//GEN-LAST:event_timer1OnTime

    private void jmiCadSalasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmiCadSalasMouseClicked
// TODO adicione seu c?digo de manipula??o aqui:
         
    }//GEN-LAST:event_jmiCadSalasMouseClicked

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        JasperReportExemplo r = new JasperReportExemplo();
    }//GEN-LAST:event_jMenuItem2ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar JMBprincipal;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbCadCliente;
    private javax.swing.JButton jbCadReserva;
    private javax.swing.JButton jbCalculadora;
    private javax.swing.JMenu jmAjuda;
    private javax.swing.JMenu jmCadastro;
    private javax.swing.JMenu jmRelatorios;
    private javax.swing.JMenu jmUtilitarios;
    private javax.swing.JMenuItem jmiCadClientes;
    private javax.swing.JMenuItem jmiCadFilmes;
    private javax.swing.JMenuItem jmiCadFunc;
    private javax.swing.JMenuItem jmiCadReserva;
    private javax.swing.JMenuItem jmiCadSalas;
    private javax.swing.JMenuItem jmiCadSessao;
    private javax.swing.JMenuItem jmiSair;
    private javax.swing.JPanel jpBotoes;
    // End of variables declaration//GEN-END:variables
    private String nameXml = "conexao.xml";
    private Database bd;
    public  String path = "/cartazes";
}
